package vn.edu.uit.hotelbooking.CustomView;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;

public class CustomDialog extends Dialog {        
    private String title;
    private String message;
    private int icon;
    private Boolean cancelable;
    private Context context;
    private String positiveText;
    private String nagativeText;
    public myOnPositiveClickListener myPositiveListener;
    public myOnNagativeClickListener myNagativeListener;
    // This is my interface //
    public interface myOnPositiveClickListener {
        void onButtonClick();
    }
    
    // This is my interface //
    public interface myOnNagativeClickListener {
        void onButtonClick();
    }
    
    public CustomDialog(Context context, String title, String message, Boolean cancelable, int icon, String positiveText, String nagativeText, myOnPositiveClickListener myPositiveClick, myOnNagativeClickListener myNegativeClick) {
        super(context);
        this.myPositiveListener = myPositiveClick;        
        this.myNagativeListener = myNegativeClick;
        this.context = context;
        this.title = title;
        this.message = message;
        this.icon = icon;
        this.cancelable = cancelable;
        this.positiveText = positiveText;
        this.nagativeText = nagativeText;
    }

    /*@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        if(!cancelable){
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    context);
            builder.setTitle(title)
                    .setMessage(message)
                    .setCancelable(cancelable)
                    .setIcon(icon)
                    .setPositiveButton(positiveText,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    myPositiveListener.onButtonClick();
                                    dialog.dismiss();
                                }
                            });
            AlertDialog alert = builder.create();
            alert.show();
        }
        else {
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    context);
            builder.setTitle(title)
                    .setMessage(message)
                    .setCancelable(cancelable)
                    .setIcon(icon)
                    .setPositiveButton(positiveText,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    myPositiveListener.onButtonClick();
                                    dialog.dismiss();
                                }
                            })
                    .setNegativeButton(nagativeText,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    myNagativeListener.onButtonClick();
                                    dialog.dismiss();
                                }
                            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    }*/
    public AlertDialog OnCreateAlert(){
        if(!cancelable){
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    context);
            builder.setTitle(title)
                    .setMessage(message)
                    .setCancelable(cancelable)
                    .setIcon(icon)
                    .setPositiveButton(positiveText,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    myPositiveListener.onButtonClick();
                                    dialog.dismiss();
                                }
                            });
            AlertDialog alert = builder.create();
            return alert;
        }
        else {
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    context);
            builder.setTitle(title)
                    .setMessage(message)
                    .setCancelable(cancelable)
                    .setIcon(icon)
                    .setPositiveButton(positiveText,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    myPositiveListener.onButtonClick();
                                    dialog.dismiss();
                                }
                            })
                    .setNegativeButton(nagativeText,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    myNagativeListener.onButtonClick();
                                    dialog.dismiss();
                                }
                            });
            AlertDialog alert = builder.create();
            return alert;
        }
    }
}
